home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / program / libkb100.zip / LIBKB-1.00 / UTIL / VT.C < prev   
C/C++ Source or Header  |  1996-07-23  |  2KB  |  111 lines

  1. /* vt.c -- Linux VT test program
  2.  * Copyright (C) 1996 Markus F.X.J. Oberhumer
  3.  * For conditions of distribution and use, see copyright notice in kb.h 
  4.  */
  5.  
  6.  
  7.  
  8. #if !defined(__linux__)
  9. #  error this program is for Linux only
  10. #endif
  11.  
  12. #include <stdlib.h>
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <unistd.h>
  16. #include <fcntl.h>
  17. #include <termios.h>
  18. #include <sys/types.h>
  19. #include <sys/ioctl.h>
  20. #include <linux/kd.h>
  21. #include <linux/vt.h>
  22.  
  23.  
  24. /***********************************************************************
  25. // test if VT-ioctl stuff works with any valid file descriptor
  26. ************************************************************************/
  27.  
  28. int vt_test(int fd, int print, int *vt, int *vt_fno)
  29. {
  30.     struct vt_stat vtinfo;
  31.     long first_non_opened;
  32.  
  33.     if (ioctl(fd, VT_GETSTATE, &vtinfo) != 0)
  34.     {
  35.         perror("ioctl VT_GETSTATE");
  36.         return -1;
  37.     }
  38.     else if (print)
  39.     {
  40.         fprintf(stdout,"info: fd: %d  vt_stat: v_active=%d "
  41.             "v_signal=0x%x v_state=0x%x\n", fd, (int) vtinfo.v_active,
  42.             (unsigned) vtinfo.v_signal, (unsigned) vtinfo.v_state);
  43.     }
  44.  
  45.  
  46.     if (ioctl(fd, VT_OPENQRY, &first_non_opened) != 0)
  47.     {
  48.         perror("ioctl VT_OPENQRY");
  49.         return -1;
  50.     }
  51.     else if (print)
  52.     {
  53.         fprintf(stdout,"info: fd: %d  first non opened VT: %ld\n",
  54.             fd, first_non_opened);
  55.     }
  56.  
  57.     if (vt)
  58.         *vt = vtinfo.v_active;
  59.     if (vt_fno)
  60.         *vt_fno = first_non_opened;
  61.     return 0;
  62. }
  63.     
  64.  
  65. /***********************************************************************
  66. // 
  67. ************************************************************************/
  68.  
  69. int main(int argc, char *argv[])
  70. {
  71.     int opt_timings = 0;
  72.     int fd;
  73.     int i;
  74.     int vt = 0, vt_fno = 0;
  75.  
  76.     /* option -t: */
  77.     if (argc == 2 && strncmp(argv[1],"-t",2) == 0)
  78.         opt_timings = 1;
  79.  
  80.  
  81.     fd = fileno(stdin);        /* ok */
  82.     fd = -1;                /* doesn't work */
  83.     fd = 0;                    /* ok */
  84.  
  85.     if (opt_timings)
  86.     {
  87.         for (i = 100000; i > 0; i--)
  88.             vt_test(fd,0,NULL,NULL);
  89.     }
  90.     else
  91.         vt_test(fd,1,&vt,&vt_fno);
  92.  
  93.  
  94. #if 0
  95.     /* switch to the next console */
  96.     if (vt > 0 && vt + 1 < vt_fno)
  97.     {
  98.         if (ioctl(fd, VT_ACTIVATE, vt + 1) != 0)
  99.             perror("ioctl VT_ACTIVATE");
  100.     }
  101. #endif
  102.         
  103.  
  104.     return 0;
  105. }
  106.  
  107.  
  108. /*
  109. vi:ts=4
  110. */
  111.